package com.common.bean;


import org.json.JSONException;
import org.json.JSONObject;

import com.common.allCommon.JSONObjecthelper;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;




/**
 * 动态消息数据结构体
 * <br>Created 2014-5-7 下午8:27:12
 * @version  
 * @author   linsj		
 *
 * @see 	 
 */
public class DynamicMsgData extends AppMsgData implements Parcelable {
	/**动态消息类型　KEY名*/
	public static String KEY_TYPE = "type";	
	/**动态消息内容 key名*/
	public static String KEY_MSG = "msg";
	/**动态消息时间戳 key名*/
	public static String KEY_TIME_STAMP = "ts";
	/**UID key名*/
	public static String KEY_UID = "uid";
	/**昵称 key名*/
	public static String KEY_NICK_NAME = "nickname";
	/**tid key名*/
	public static String KEY_TID = "tid";
	/**图片链接 key名*/
	public static String KEY_PIC_URL= "picurl";
	/**摘要 key名*/
	public static String KEY_SUMMARY = "summary";
	
	/**消息类型*/
	public String strType = null;
	/**消息内容*/
	public String strMsg = null;
	/**被赞被评论的服务端时间戳*/
	public long lTimeStamp = 0;
	/**用户编号 */
	public long lUid = 0;
	/**用户昵称*/
	public String strNickName = null;
	/**被操作的动态的id值*/
	public long lTid = 0;
	/**原动态首张图片 和summary二选一(picurl优先) */
	public String strPicURL = null;
	/**原动态文字缩略 和picurl二选一(picurl优先) */
	public String strSummary = null;
	
	/**
	 * Creates a new instance of NourishData.
	 *
	 */
	public DynamicMsgData(){
		
	}
	
	public static final Parcelable.Creator<DynamicMsgData> CREATOR = new Parcelable.Creator<DynamicMsgData>() {
		public DynamicMsgData createFromParcel(Parcel in) {
			return new DynamicMsgData(in);
		}

		public DynamicMsgData[] newArray(int size) {
			return new DynamicMsgData[size];
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}
	
	
	
	/**
	 * 序列化.
	 * <br>Created 2014-5-7 下午8:27:43
	 * @param in 写入参数
	 */
	private DynamicMsgData(Parcel in) {
		super.parcelInData(in);
		strType = in.readString();
		strMsg = in.readString();
		lTimeStamp = in.readLong();
		lUid = in.readLong();
		strNickName = in.readString();
		lTid = in.readLong();
		strPicURL = in.readString();
		strSummary = in.readString();
	}
	
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);
		dest.writeString(strType);
		dest.writeString(strMsg);
		dest.writeLong(lTimeStamp);
		dest.writeLong(lUid);
		dest.writeString(strNickName);
		dest.writeLong(lTid);
		dest.writeString(strPicURL);
		dest.writeString(strSummary);
	}

	@Override
	public void parseJson(String strJson) {
		if(TextUtils.isEmpty(strJson)){
			return;
		}	
		
		JSONObject jsonData = null;
		try {
			jsonData = new JSONObject(strJson);
		} catch (JSONException e) {
			return;
		}
		
		lMsgID = JSONObjecthelper.getLong(jsonData, "msg_id");
		strType = JSONObjecthelper.getString(jsonData, "type");
		strMsg = JSONObjecthelper.getString(jsonData, "msg");
		lTimeStamp = JSONObjecthelper.getLong(jsonData, "ts");
		lUid = JSONObjecthelper.getLong(jsonData, "uid");
		strNickName = JSONObjecthelper.getString(jsonData, "nickname");
		lTid = JSONObjecthelper.getLong(jsonData, "tid");
		strPicURL = JSONObjecthelper.getString(jsonData, "picurl");
		strSummary = JSONObjecthelper.getString(jsonData, "summary");
	}
}
